import uvicorn
from fastapi import FastAPI
# 安装 pip install  fastapi
# 安装 pip install  Uvicorn

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "你好，FastAPI！"}

@app.get("/user/{user_id}")
def read_user(user_id: int):
    return {"user_id": user_id, "status": "active"}

# 命令行启动：uvicorn 02FastAPI:app --reload
# 代码启动：
if __name__ == '__main__':
    uvicorn.run('02FastAPI:app',port=8080,reload=True)

# 访问服务
# http://localhost:8080

# 打开swagger文档
# http://localhost:8080/docs